import 'package:get/get.dart';

class DomainTitleModel {
  final String name;
  final String key;
  final bool? selected;
  final int? state;

  const DomainTitleModel({
    required this.name,
    required this.key,
    this.selected,
    this.state = 0,
  });

  DomainTitleModel copyWith({
    String? name,
    String? key,
    bool? selected,
    int? state,
  }) {
    return DomainTitleModel(
      name: name ?? this.name,
      key: key ?? this.key,
      selected: selected ?? this.selected,
      state: state ?? this.state,
    );
  }
}

// 2. 响应式操作方法
extension DomainTitleListExtensions on RxList<Rx<DomainTitleModel>> {
  /// 批量更新状态值
  void updateAllStates(int newState) {
    forEach((rxModel) {
      rxModel.update((model) => model?.copyWith(state: newState));
    });
  }

  /// 重置所有状态为0
  void resetAllStates() => updateAllStates(0);
}
